﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp7
{
    class DbHelper
    {
        public static readonly string conString = "server=. ;database=Blogs;uid=SunBoy;pwd=010927";
        /// <summary>
        /// 查找
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static DataTable GetDataTable(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(conString);
            SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, sqlConnection);
            DataTable data = new DataTable();
            sqlConnection.Open();
            dataAdapter.Fill(data);
            return data;
        }
        /// <summary>
        /// 添加删除修改
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static int AddOrAddOrEditOrDeleteSave(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(conString);
            SqlCommand command = new SqlCommand(sql, sqlConnection);
            sqlConnection.Open();
            return command.ExecuteNonQuery();
        }
    }
}
